<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.code" placeholder="成品件号" style="width: 100px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-input v-model="listQuery.oldCode" placeholder="老编码" style="width: 100px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-input v-model="listQuery.workpieceCode" placeholder="工件型号编码" style="width: 150px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-input v-model="listQuery.pch" placeholder="批次号" style="width: 100px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-input v-model="listQuery.finishMonth" placeholder="完成月份" style="width: 100px;" class="filter-item" @keyup.enter.native="handleFilter" />

      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>
    </div>

    <el-table
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row>
      <el-table-column label="品种" align="center">
        <el-table-column label="成品件号" align="center" >
          <template slot-scope="scope">
            {{ scope.row.code }}
          </template>
        </el-table-column>
        <el-table-column label="老编码" align="center" >
          <template slot-scope="scope">
            {{ scope.row.oldCode }}
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label=" " align="center" width="40">

      </el-table-column>
      <el-table-column label="工件型号编码" align="center">
        <template slot-scope="scope">
          {{ scope.row.workpieceCode }}
        </template>
      </el-table-column>
      <el-table-column label="批次号" align="center">
        <template slot-scope="scope">
          {{ scope.row.pch }}
        </template>
      </el-table-column>
      <el-table-column label="产出数量" align="center">
        <el-table-column label="初期数" align="center">
          <template slot-scope="scope">
            <p v-if="scope.row.cqs!=0" style="margin: 0; padding: 0;">{{ scope.row.cqs }}</p>
            <p v-else style="margin: 0; padding: 0; color: #d3dce6;">{{ scope.row.cqs }}</p>
          </template>
        </el-table-column>
        <el-table-column label="主齿元车完成数量" align="center">
          <el-table-column v-for="i in 31" :label="i" align="center">
            <template slot-scope="scope">
              <p v-if="scope.row.dailyFinish[i-1]!=0" style="margin: 0; padding: 0;">{{ scope.row.dailyFinish[i-1] }}</p>
              <p v-else style="margin: 0; padding: 0; color: #d3dce6;">{{ scope.row.dailyFinish[i-1] }}</p>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="本月完成" >
          <template slot-scope="scope">
            <p v-if="scope.row.monthFinish!=0" style="margin: 0; padding: 0;">{{ scope.row.monthFinish }}</p>
            <p v-else style="margin: 0; padding: 0; color: #d3dce6;">{{ scope.row.monthFinish }}</p>
          </template>
        </el-table-column>
        <el-table-column label="累计完成" >
          <template slot-scope="scope">
            <p v-if="scope.row.totalFinish!=0" style="margin: 0; padding: 0;">{{ scope.row.totalFinish }}</p>
            <p v-else style="margin: 0; padding: 0; color: #d3dce6;">{{ scope.row.totalFinish }}</p>
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

  </div>
</template>

<script>
import { fetchList } from '@/api/yuanche'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      total: 0,
      listQuery: {
        page: 1,
        limit: 20,
        code: undefined,
        oldCode: undefined,
        workpieceCode: undefined,
        pch: undefined,
        finishMonth: '2019-01'
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        this.list = response.data.items
        this.total = response.data.total

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    }
  }
}
</script>
